package com.herench.bs.handler;

import com.herench.bs.agent.IOutpatientClinicAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import com.herench.bs.utils.ValidateUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.Map;

/**
 * Created by ThinkPad on 2017/9/23.
 */
@Component
@Handler(code = "100235",name="发送验证码")
public class SendVerificationCodeHandler extends AbstractMessageHandler {

    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = new ResponseMessage(requestMessage.getId());
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");
        Assert.hasLength(channelCode, "sysCode 为空");
        String user = requestMessage.getArgsPropertyStringValue("user");
        Assert.hasLength(user, "user 为空");
        Assert.isTrue(ValidateUtils.validPhoneNum("0", user), "请输入正确的手机号");
        String type = requestMessage.getArgsPropertyStringValue("type");//1 : 登录密码 2:注册密码 ；3: 修改密码验证码
        Assert.hasLength(type, "type 为空");

        IOutpatientClinicAgent agent = getCleverClinicContext().getApplicationContext().getBean(IOutpatientClinicAgent.class);
        Map<String, Object> res = agent.sendVerificationCode(channelCode, type, user);
        getPropertiesFromInvokerResultMap(responseMessage,res);
        return responseMessage;
    }
}
